<template>
    <!--    装备-->
    <el-dialog  title="装备上架" width="90%">
        <el-form ref="form" :model="form" label-width="60px">
            <el-form-item label="物品" >
                <el-cascader :options="goodsDatas" v-model="form.name"
                             :show-all-levels="false"
                             popper-class="caStyle"
                             @change="handleChange"
                ></el-cascader>
                <div>{{form.name}}</div>
            </el-form-item>
            <el-form-item label="属性">
                <el-input  v-model="form.property" placeholder="输入如：耐久3"></el-input>
            </el-form-item>
            <el-form-item label="宝石属性">
                <el-input  v-model="form.bsProperty" placeholder="输入如：反馈4"></el-input>
            </el-form-item>
            <el-form-item label="数量">
                <el-input  v-model="form.number"></el-input>
            </el-form-item>
            <el-form-item label="剩余耐久">
                <el-input  v-model="form.blood" placeholder="输入如：10%"></el-input>
            </el-form-item>
            <el-form-item label="价格" class="price">
                <div style="display:flex">
                    <el-input  v-model="form.price" placeholder="请输入价格"></el-input>
                    <el-select v-model="form.priceUnit" placeholder="请选择单位">
                        <el-option
                                v-for="item in priceUnitdata"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </div>
            </el-form-item>
            <el-form-item label="服务器">
                <el-select v-model="form.fwq" placeholder="请选择服务器">
                    <el-option
                            v-for="item in fwqdata"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="地址">
                <el-input  v-model="form.address" placeholder="输入如：1南梅盖拉1人东面"></el-input>
            </el-form-item>

        </el-form>
        <template #footer>
                    <span class="dialog-footer">
                        <el-button type="primary" @click="uodate">上架</el-button>
                        <el-button type="primary" @click="$store.state.dialogVisible1 = false">取消</el-button>
                    </span>
        </template>
    </el-dialog>
</template>

<script>
    import request from "../../network/request";
    import fwq from "../../assets/js/fwq";
    import zb from "../../assets/js/zhuangb";

    export default {
        name: "UpTCt",
        data(){
            return{
                user : JSON.parse(sessionStorage.getItem("user")),
                form:{number:1},
                ls:{},
                dialogVisible1:true,
                goodsDatas:zb,
                priceUnitdata: [
                    {
                        value: '结晶',
                        label: '结晶'
                    }, {
                        value: '钻块',
                        label: '钻块'
                    }, {
                        value: '钻石',
                        label: '钻石'
                    },],
                fwqdata:fwq
            }
        },
        created() {
            this.form.address = this.user.address
            this.form.fwq = this.user.fwq
            this.form.author = this.user.username
        },
        methods:{
            handleChange(value){
                this.ls.goods =value.filter(function(val){
                    return val && val.trim();
                });
                this.form.clazz=this.ls.goods[0]
                this.form.name=this.ls.goods[1]
            },
            uodate(){
                request.post("/goods",this.form).then(res => {
                    console.log(res)
                    if (res.code === '0'){
                        this.$message({
                            type: "success",
                            message: "上架成功啦"
                        })
                    } else {
                        this.$message({
                            type: "error",
                            message: res.msg
                        })
                    }
                    this.$store.state.dialogVisible1 = false  //关闭弹窗
                })
            }
        }
    }
</script>

<style scoped>

</style>